package functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.program;

/**
 * An abstract class with three methods that all Program objects are required to have. Firstly, a
 * method to set the required set of arguments, secondly set the map that contains those arguments
 * and the appropriate argument values and thirdly a run() method that should be implemented.
 * @author Jamie MacPherson
 */
public abstract class Program {

    // the arguments that are required for the program to work
    protected Argument[] requiredArguments;

    // A map containing the arguments and their values
    protected ArgumentMap argumentMap;

    /**
     * An array of Argument objects that are the minimum requirement for that program to run.
     * @param arguments the array of Argument objects
     */
    public void setRequiredArguments(Argument[] arguments){
        this.requiredArguments = arguments;
    }

    /**
     * Sets a field as an <code>ArgumentMap</code> object. The method checks the map of arguments
     * that are passed in against the required arguments. If one of the required arguments is
     * missing, an exception is thrown.
     * @param argumentMap a map containing the arguments and their values.
     * @throws IllegalArgumentException if the required arguments are not all met.
     */

    public void setArgumentMap(ArgumentMap argumentMap) throws IllegalArgumentException{
        for(Argument requiredArgument : requiredArguments){
            if(!argumentMap.containsKey(requiredArgument)){
                throw new IllegalArgumentException("To run this program, you must specify the argument -"+requiredArgument.toString().toLowerCase()+" ("+requiredArgument.getTag()+")");
            } 
        }
        this.argumentMap = argumentMap;
    }

    /**
     * runs the program
     */

    public abstract void run();

}
